# -------------------------------------------------------------------
#       -*- coding: utf-8 -*-
#   @Project    :   spider
#   @File       :   46_协程-爬虫.py
#   @Author     :   WANGYU
#   @Time       :   2021-09-04 09:17:21
#   @Software   :   PyCharm
#   @Desc       :   
# -------------------------------------------------------------------


# 在爬虫领域的应用
import asyncio


async def download():
    print('开始下载')
    await asyncio.sleep(2) #换成网络请求
    print('下载完成')

async def main():
    urls=[
        'http://www.baidu.com',
        'http://www.bilibili.com',
        'http://www.163.com'
    ]
    tasks = []
    for url in urls:
        d=download(url)
        tasks.append(d)
    await asyncio.wait(tasks)

if __name__ == '__main__':
    asyncio.run(main())